package com.ff.dao;

import java.io.IOException;
import java.io.InputStream;

import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.model.OSSObject;
import com.aliyun.oss.model.ObjectListing;

public interface OssDao {

	/**
	 * 确认bucket存在,不存在则创建
	 * @param client
	 * @param bucketName
	 * @throws OSSException
	 * @throws ClientException
	 */
    public void ensureBucket(OSSClient client, String bucketName) throws OSSException, ClientException;

    /**
     * 查看文件是否存在
     * @param client
     * @param bucketName
     * @param key
     * @return
     * @throws OSSException
     * @throws ClientException
     */
    public OSSObject findObject(OSSClient client, String bucketName, String key) throws OSSException, ClientException;

    /**
     * 创建文件夹
     * @param client
     * @param bucketName
     * @param folderName
     * @throws IOException
     */
    public void createFolder(OSSClient client, String bucketName, String folderName) throws IOException;

    /**
     * 上传文件
     * @param client 客户端
     * @param bucketName bucket名称
     * @param key id
     * @param contentType 文件类型
     * @param contentLength 文件长度
     * @param input 输入流
     * @throws OSSException
     * @throws ClientException
     */
    public void uploadFile(OSSClient client, String bucketName, String key, String contentType, long contentLength, InputStream input) throws OSSException, ClientException;

    /**
     * 根据bucket名称和 key 查找图片
     * @param client
     * @param bucketName
     * @param key
     * @return
     * @throws ClientException
     */
    public String getObjectUri(OSSClient client, String bucketName, String key) throws ClientException;

    /**
     * 根据bucket名称和 key 删除图片
     * @param client
     * @param bucketName
     * @param key
     * @return
     * @throws OSSException
     * @throws ClientException
     */
    public boolean deleteObject(OSSClient client, String bucketName, String key) throws OSSException, ClientException;
    
    /**
     * 根据bucket名称获取文件夹下的全部图片
     * @param client
     * @param bucketName
     * @param folderName
     * @return
     * @throws OSSException
     * @throws ClientException
     */
    public ObjectListing listObject(OSSClient client, String bucketName, String folderName) throws OSSException, ClientException;

	/**
	 * @Title: getPrivatePicUri
	 * @Description: OSS私有文件临时授权url
	 * @param client
	 * @param bucket
	 * @param key
	 * @param expiration 
	 * @return
	 * @return: String
	 */
	public String getPrivatePicUri(OSSClient client, String bucket, String key, Integer expiration);
}
